<?php
//open database
require_once('../../controller/auth.php');
//Start session
	session_start();
	
	//Include database connection details
	require_once('../../controller/inc/config.inc');
	
	//Array to store validation errors
	$errmsg_arr = array();
	
	//Validation error flag
	$errflag = false;
	
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db("ttc_teachers");
	if(!$db) {
		die("Unable to select database");
	}
	

//include our awesome pagination
//class (library)
include 'ps_pagination.php';

//query all data anyway you want
//$sql = "select * from students ORDER BY stu_id DESC";
mysql_query ('SET NAMES utf8');
mysql_query('SET CHARACTER_SET utf8');
$sql = "SELECT * from tblteachers ORDER BY ID";
//execute query and get and

$rs = mysql_query( $sql ) or die('Database Error: ' . mysql_error() . ' ' . $sql );

//now, where gonna use our pagination class
//this is a significant part of our pagination
//i will explain the PS_Pagination parameters
//$conn is a variable from our config_open_db.php
//$sql is our sql statement above
//3 is the number of records retrieved per page
//4 is the number of page numbers rendered below
//null - i used null since in dont have any other
//parameters to pass (i.e. param1=valu1&param2=value2)
//you can use this if you're gonna use this class for search
//results since you will have to pass search keywords
$pager = new PS_Pagination( $link, $sql, 10, 12, null );

//our pagination class will render new
//recordset (search results now are limited
//for pagination)
$rs = $pager->paginate(); 

//get retrieved rows to check if
//there are retrieved data
$num = mysql_num_rows( $rs );

if($num >= 1 ){     
	//creating our table header
	echo "<form method='post'>";
	echo "<table class='table table-bordered table-hover'>";
	echo "<tr class='well'>";
		echo "<th>S/N</th>";
		echo "<th>Name</th>";
		echo "<th>Father Name</th>";
		echo "<th>Gender</th>";
		echo "<th>Province</th>";
		echo "<th>Education Level</th>";
		echo "<th>Education Field</th>";
		echo "<th>Academic Grade</th>";
		echo "<th>Appionted TTC Location</th>";
		echo "<th colspan='3' style='text-align:center'>Actions</th>";
	echo "</tr>";
	$genderArray=array(1=>'Male',2=>'Female');
	//looping through the records retrieved
	while($row = mysql_fetch_array( $rs )){
		//echo "<tr class='bar$row[stu_id]'>";
		//echo "<td>{$row['first_name']}</td>";
		//echo "<td>{$row['sure_name']}</td>";
		//echo "<td>{$row['email']}</td>";
		//echo "<td>{$row['paid']}</td>";
		//echo "<td>{$row['due']}</td>";
		//echo "<td>{$row['nid']}</td>";
		
		//--------
		echo "<tr class='bar$row[id]'>";
		echo "<td>{$row['ID']}</td>";
		echo "<td>{$row['NAME']}</td>";
		echo "<td>{$row['FATHER_NAME']}</td>";
		echo "<td>{$genderArray[$row['GENDER']]}</td>";
		echo "<td>{$row['PROVINCE']}</td>";
		
		
		echo "<td>{$row['EDUCATION_LEVEL']}</td>";
		echo "<td>{$row['EDUCATION_FIELD']}</td>";
		echo "<td>{$row['ACADEMIC_GRADE']}</td>";
		echo "<td>{$row['APPOINTED_TTC_LOCATION']}</td>";
		//-------
		
		echo "<td style='text-align:center'><a href='edit.php?id=$row[ID]'><i class='icon-pencil'></i></a></td>";
		echo "<td style='text-align:center'><a href='javascript:void' id='$row[ID]' class='delete_update' alt='Delete'><i class='icon-trash'></i></a></td>";
		echo "<td style='text-align:center'><a href='controller/addStudent_ac.php?id=$row[ID]' alt='Print'><i class='icon-print'></i></a></td>";
		echo "</tr>";
	}       
	
	echo "</table>";
	echo "</form>";
}else{
	//if no records found
	echo "No records found!" . mysql_error();
}
//page-nav class to control
//the appearance of our page 
//number navigation
echo "<div class='pagination'>";
	//display our page number navigation
	echo $pager->renderFullNav();
echo "</div>";

?>